<template>
  <div class="photoinfo-container">
    <h3>{{ photoinfo.title }}</h3>
    <p class="subtitle">
      <span>发表时间：{{ photoinfo.add_time | dateFormat }}</span>
      <span>点击：{{ photoinfo.click }}次</span>
    </p>
    <hr />
    <!-- 缩略图区域 -->
    <div class="thumbs">
      <vue-preview :slides="slide1" @close="handleClose"></vue-preview>
    </div>
    <!-- 内容区域 -->
    <div class="content" v-html="photoinfo.content"></div>
    <!-- 放置现有的评论子组件 -->
    <!-- 3. 以标签形式渲染到界面上 ,子组件需要传入对应的id属性，-->
    <cmt-box :id="id"></cmt-box>
  </div>
</template>

<script>
// 1. 导入评论子组件
import comment from "../subcomponents/comment.vue";
export default {
  data() {
    return {
      id: this.$route.params.id, //将页面id挂载到data上，方便后续调用
      photoinfo: {}, //存放所有的图片详情的数据
      slide1: [] //存放缩略图所有的数据
    };
  },
  created() {
    this.getPhotoInfo();
    this.getThumbs();
  },
  methods: {
    getPhotoInfo() {
      this.$axios
        .get("/api/getimageInfo/" + this.id)
        .then(response => {
          this.photoinfo = response.data.message[0];
        })
        .catch(err => {
          console.log(err);
        });
    },
    getThumbs() {
      //获取缩略图
      this.$axios.get("/api/getthumimages/" + this.id).then(response => {
        response.data.message.forEach(item => {
          item.w = 600;
          item.h = 400;
          item.msrc = item.src;
          item.alt = "picture1";
          item.title = "Image Caption 1";
        });
        this.slide1 = response.data.message;
      });
    },
    handleClose() {
      console.log("close event");
    }
  },
  components: {
    "cmt-box": comment //注册  评论子组件
  }
};
</script>

<style lang="scss" scoped>
.photoinfo-container {
  padding: 3px;
  h3 {
    font-size: 15px;
    color: #26a2ff;
    text-align: center;
    margin: 15px 0;
  }
  .subtitle {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
  }
  .content {
    font-size: 14px;
    line-height: 30px;
  }

  .thumbs {
    /deep/ .my-gallery {
      //deep深层作用选择器
      display: flex;
      flex-wrap: wrap; //默认换行
      figure {
        width: 30%;
        margin: 5px;
        img {
          width: 100%;
          box-shadow: 0 0 8px #999;
          border-radius: 5px;
        }
      }
    }
  }
}
</style>